// 这个文件是 "main.dart"
import 'package:flutter_reactive_ble/flutter_reactive_ble.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:flutter/foundation.dart';
import 'package:sleep/model/blue_connection_state.dart';

part 'blue_model.freezed.dart';
part 'blue_model.g.dart';

enum BlueConnectType { fatigue, sleep, pulse }

@freezed
class BlueModel with _$BlueModel {
  const factory BlueModel({
    required String name,
    required String deviceId,
    String? serverId,
    String? alias,
    BlueConnectionState? connectionState,
    BlueConnectType? type,
  }) = _BlueModel;

  factory BlueModel.fromJson(Map<String, Object?> json) =>
      _$BlueModelFromJson(json);

  static BlueModel toBlueModel(DiscoveredDevice device) {
    return BlueModel(deviceId: device.id, name: device.name);
  }
}
